﻿package baseEngine.core
{
    import __AS3__.vec.*;
    import baseEngine.basic.*;
    import baseEngine.events.*;
    import baseEngine.materials.*;
    import baseEngine.modifiers.*;
    import baseEngine.system.*;
    import baseEngine.utils.*;
    import flash.display.*;
    import flash.geom.*;
    import frEngine.*;
    import frEngine.animateControler.*;
    import frEngine.animateControler.colorControler.*;
    import frEngine.animateControler.keyframe.*;
    import frEngine.animateControler.uvControler.*;
    import frEngine.core.*;
    import frEngine.core.mesh.*;
    import frEngine.effectEditTool.parser.*;
    import frEngine.event.*;
    import frEngine.manager.*;
    import frEngine.pools.*;
    import frEngine.primitives.*;
    import frEngine.render.*;
    import frEngine.render.layer.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.fragmentFilters.*;
    import frEngine.shader.filters.vertexFilters.*;
    import frEngine.util.*;

    public class Mesh3D extends Pivot3D
    {
        protected var surfaces:Vector.<FrSurface3D>;
        private var _bounds:Boundings3D;
        private var _boundsCenter:Vector3D;
        private var _boundsRadius:Number = 1;
        private var _updateBoundsScale:Boolean = true;
        public var mouseEnabled:Boolean = true;
        public var useHandCursor:Boolean = false;
        public var render:IRender;
        public var loadPriority:int = 3;
        public var material:ShaderBase;
        protected var _originalMaterial:ShaderBase;
        protected var _additionalMaterial:ShaderBase;
        private var _renderList:RenderList;
        public var isCirclePlay:Boolean;
        private var _oldBlendMode:int = 0;
        private var _oldLayer:int = 0;
        private var _additionMaterialList:Array;
        private static const MOUSE_DOWN:int = 1 << 7;
        private static const MOUSE_MOVE:int = 1 << 8;
        private static const MOUSE_UP:int = 1 << 9;
        private static const MATERIAL_CHANGE:int = 1 << 10;
        private static var _bScale:Vector3D = new Vector3D();
        private static var _bCenter:Vector3D = new Vector3D();

        public function Mesh3D(param1:String, param2:Boolean, param3:RenderList)
        {
            this._additionMaterialList = [];
            this.render = DefaultRender.instance;
            this.surfaces = new Vector.<FrSurface3D>;
            this._boundsCenter = new Vector3D();
            this._renderList = param3;
            super(param1);
            var _loc_4:* = new ShaderBase("material:" + this.name, null, null);
            this.material = new ShaderBase("material:" + this.name, null, null);
            this._originalMaterial = _loc_4;
            return;
        }// end function

        public function changeOriginalMaterial(param1:ShaderBase) : void
        {
            if (param1)
            {
                var _loc_2:* = param1;
                this.material = param1;
                this._originalMaterial = _loc_2;
            }
            return;
        }// end function

        public function drawShadow() : void
        {
            return;
        }// end function

        public function setCirclePlay(param1:Boolean) : void
        {
            if (param1 == this.isCirclePlay)
            {
                return;
            }
            this.isCirclePlay = param1;
            return;
        }// end function

        public function setBlendModeAndKillAlpha(param1:Boolean, param2:Number = 0.1, param3:int = 4) : void
        {
            if (this.material.materialParams.unlevelAlpha == 1 && this.alpha == 1)
            {
                this.setMateiralBlendMode(param3);
            }
            else
            {
                this._oldBlendMode = param3;
            }
            if (param2 > 0)
            {
                ParserLayerObject.instance.parserAlphaKil(this._originalMaterial.materialParams, param1, param2);
            }
            return;
        }// end function

        public function set renderList(param1:RenderList) : void
        {
            if (param1 != this._renderList)
            {
                this._renderList = param1;
            }
            if (this._renderList && this._scene)
            {
                this._renderList.insertIntoList(this);
            }
            return;
        }// end function

        public function get renderList() : RenderList
        {
            return this._renderList;
        }// end function

        final public function getSurface(param1:int) : FrSurface3D
        {
            if (param1 < this.surfaces.length)
            {
                return this.surfaces[param1];
            }
            return null;
        }// end function

        final public function getSurfacesLen() : int
        {
            return this.surfaces.length;
        }// end function

        public function setSurface(param1:int, param2:FrSurface3D) : void
        {
            if (this.surfaces.indexOf(param2) == -1)
            {
                this.surfaces[param1] = param2;
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.SetMeshSurface);
            }
            return;
        }// end function

        public function addSurface(param1:FrSurface3D) : void
        {
            this.setSurface(this.surfaces.length, param1);
            return;
        }// end function

        public function clearSurface() : void
        {
            this.surfaces.length = 0;
            return;
        }// end function

        override public function getAnimateControlerInstance(param1:int, param2:Modifier = null) : Modifier
        {
            var _loc_3:* = super.getAnimateControlerInstance(param1, param2);
            if (_loc_3 == null)
            {
                switch(param1)
                {
                    case AnimateControlerType.DefaultAnimateControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(Modifier, this));
                        break;
                    }
                    case AnimateControlerType.DrawShapeControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(DrawShapeControler, this));
                        break;
                    }
                    case AnimateControlerType.UvStepControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(FrUvStepControler, this));
                        break;
                    }
                    case AnimateControlerType.UoffsetControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(UoffsetControler, this));
                        break;
                    }
                    case AnimateControlerType.VoffsetControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(VoffsetControler, this));
                        break;
                    }
                    case AnimateControlerType.colorAnimateControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(ColorControler, this));
                        break;
                    }
                    case AnimateControlerType.alphaAnimateControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(AlphaControler, this));
                        break;
                    }
                    case AnimateControlerType.blightAnimateControler:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(BlightControler, this));
                        break;
                    }
                    case AnimateControlerType.UVRotateAnimationController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(UVRotateController, this));
                        break;
                    }
                    case AnimateControlerType.UVCenterScaleController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(UVCenterScaleControler, this));
                        break;
                    }
                    case AnimateControlerType.RimLightController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(RimLightControler, this));
                        break;
                    }
                    case AnimateControlerType.SimpleWaterController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(SimpleWaterController, this));
                        break;
                    }
                    case AnimateControlerType.MaskUController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(MaskUController, this));
                        break;
                    }
                    case AnimateControlerType.MaskVController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(MaskVController, this));
                        break;
                    }
                    case AnimateControlerType.MaskUVScaleController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(MaskUVScaleController, this));
                        break;
                    }
                    case AnimateControlerType.MaskUVRotController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(MaskUVRotController, this));
                        break;
                    }
                    case AnimateControlerType.MaskAlphaController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(MaskAlphaControl, this));
                        break;
                    }
                    case AnimateControlerType.RimLightStrengthController:
                    {
                        _loc_3 = param2 ? (param2) : (FrObjectPool.getObject(RimLightStrengthController, this));
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                if (_loc_3)
                {
                    _animateControlerList[param1] = _loc_3;
                    _loc_3.targetObject3d = this;
                    if (_loc_3 is IRender)
                    {
                        this.render = IRender(_loc_3);
                    }
                }
            }
            return _loc_3;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            if (isDisposed)
            {
                return;
            }
            this._additionMaterialList.length = 0;
            this._bounds = null;
            this.material = this._originalMaterial;
            this.setUvScaleBase(1, 1);
            this.setUvOffsetBase(0, 0);
            this.disposeSurfaces();
            super.dispose(param1);
            this.disposeMaterials();
            this._oldBlendMode = 0;
            this._oldLayer = 0;
            return;
        }// end function

        public function disposeSurfaces() : void
        {
            this.surfaces = new Vector.<FrSurface3D>;
            return;
        }// end function

        public function disposeMaterials() : void
        {
            this._originalMaterial.dispose();
            this._additionalMaterial = null;
            return;
        }// end function

        public function setUvScaleBase(param1:Number, param2:Number) : void
        {
            if (this.isDisposed)
            {
                throw new Error("setUvScaleBase as Mesh3d.as error!");
            }
            this.material.materialParams.uvValue2[0] = param1;
            this.material.materialParams.uvValue2[1] = param2;
            return;
        }// end function

        public function setUvOffsetBase(param1:Number = -10000, param2:Number = -10000) : void
        {
            if (this.isDisposed)
            {
                throw new Error("setUvOffsetBase as Mesh3d.as error!");
            }
            var _loc_3:* = param1;
            this.material.materialParams.uvValue2[2] = param1;
            var _loc_3:* = param2;
            this.material.materialParams.uvValue2[3] = param2;
            return;
        }// end function

        override public function download(param1:Boolean = true) : void
        {
            var _loc_2:FrSurface3D = null;
            super.download(param1);
            for each (_loc_2 in this.surfaces)
            {
                
                _loc_2.download();
            }
            return;
        }// end function

        override public function clone() : Pivot3D
        {
            var _loc_1:FrSurface3D = null;
            var _loc_2:Pivot3D = null;
            var _loc_3:* = this.hasControler(AnimateControlerType.colorAnimateControler);
            var _loc_4:* = new Mesh3D(name, _loc_3, this._renderList);
            _loc_4.copyFrom(this);
            _loc_4.useHandCursor = this.useHandCursor;
            _loc_4.bounds = this._bounds;
            _loc_4._originalMaterial.materialParams.cloneFrom(this._originalMaterial.materialParams);
            for each (_loc_1 in this.surfaces)
            {
                
                _loc_4.surfaces.push(_loc_1.clone());
            }
            for each (_loc_2 in children)
            {
                
                if (!_loc_2.lock)
                {
                    _loc_4.addChild(_loc_2.clone());
                }
            }
            return _loc_4;
        }// end function

        protected function setTextureFilter(param1, param2:int) : FragmentFilter
        {
            var _loc_3:Texture3D = null;
            if (param1 is Texture3D)
            {
                _loc_3 = Texture3D(param1);
                _loc_3.loadPriority = this.loadPriority;
                param1 = new TextureFilter(_loc_3);
            }
            else
            {
                _loc_3 = Resource3dManager.instance.getTexture3d(param1, param2, this.loadPriority);
                param1 = new TextureFilter(_loc_3);
            }
            return param1;
        }// end function

        override public function setLayer(param1:int, param2:Boolean = true) : void
        {
            if (this._renderList && param1 != this.layer)
            {
                this._renderList.removeFromList(this);
                this.layer = param1;
                if (this._scene)
                {
                    this._renderList.insertIntoList(this);
                }
            }
            super.setLayer(param1, param2);
            this._oldLayer = param1;
            return;
        }// end function

        override public function removedFromScene() : void
        {
            super.removedFromScene();
            return;
        }// end function

        override public function addedToScene(param1:Scene3D) : Boolean
        {
            if (this._scene == param1)
            {
                return true;
            }
            var _loc_2:* = super.addedToScene(param1);
            if (this._renderList && this._scene && _loc_2)
            {
                this._renderList.insertIntoList(this);
            }
            else
            {
                _loc_2 = false;
            }
            return _loc_2;
        }// end function

        public function setMaterial(param1, param2:int, param3:String) : void
        {
            var _loc_4:VertexFilter = null;
            var _loc_5:FragmentFilter = null;
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_8:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            if (param1 is ShaderBase)
            {
                throw new Error("参数类型不能为ShaderBase,Mesh3D");
            }
            if (param1 is String || param1 is BitmapData || param1 is Texture3D)
            {
                _loc_5 = this.setTextureFilter(param1, param2);
            }
            else if (param1 is Number)
            {
                _loc_6 = Number(param1);
                if (_loc_6 <= 16777215)
                {
                    _loc_7 = 1;
                }
                else
                {
                    _loc_7 = ((_loc_6 & 4278190080) >> 24) / 255;
                }
                _loc_8 = ((_loc_6 & 16711680) >> 16) / 255;
                _loc_9 = ((_loc_6 & 65280) >> 8) / 255;
                _loc_10 = (_loc_6 & 255) / 255;
                _loc_5 = new ColorFilter(_loc_8, _loc_9, _loc_10, _loc_7);
            }
            else if (param1 is FragmentFilter)
            {
                _loc_5 = param1;
            }
            else if (param1 is VertexFilter)
            {
                _loc_4 = param1;
            }
            this.priority = HelpUtils.getSortIdByName(param3);
            if (this is FrPlane)
            {
                this.priority = this.priority + 100000;
            }
            else if (this is ParticleMesh)
            {
                this.priority = this.priority + 200000;
            }
            this.setShaderBase(_loc_4, _loc_5);
            return;
        }// end function

        public function setShaderBase(param1:VertexFilter, param2:FragmentFilter) : void
        {
            if (!param1)
            {
                param1 = this._originalMaterial.materialParams.vertexFilter;
            }
            if (!param1)
            {
                param1 = new TransformFilter();
            }
            this._originalMaterial.materialParams.setVertexFilter(param1);
            this._originalMaterial.materialParams.setFragmentFilter(param2);
            if (this.material is UseOriTexShaderbase && UseOriTexShaderbase(this.material).useOriginTexture)
            {
                this.material.materialParams.setFragmentFilter(param2);
            }
            if (this._eventFlags & MATERIAL_CHANGE)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.MATERIAL_CHANGE);
            }
            return;
        }// end function

        public function setMateiralBlendMode(param1:int, param2:String = "one", param3:String = "one") : void
        {
            if (param1 == this.material.materialParams.blendMode && param1 != EBlendType.BLEND_CUSTOM)
            {
                return;
            }
            this._oldBlendMode = param1;
            this.material.materialParams.setBlendMode(param1);
            if (param1 == EBlendType.BLEND_CUSTOM)
            {
                this.material.materialParams.sourceFactor = param2;
                this.material.materialParams.destFactor = param3;
            }
            return;
        }// end function

        public function updateBoundings() : void
        {
            this._bounds = null;
            this._bounds = this.bounds;
            return;
        }// end function

        public function get bounds() : Boundings3D
        {
            var _loc_1:FrSurface3D = null;
            if (this._bounds)
            {
                return this._bounds;
            }
            this._bounds = new Boundings3D();
            this._bounds.min.setTo(10000000, 10000000, 10000000);
            this._bounds.max.setTo(-10000000, -10000000, -10000000);
            for each (_loc_1 in this.surfaces)
            {
                
                if (!_loc_1.bounds)
                {
                    _loc_1.updateBoundings();
                }
                Vector3DUtils.min(_loc_1.bounds.min, this._bounds.min, this._bounds.min);
                Vector3DUtils.max(_loc_1.bounds.max, this._bounds.max, this._bounds.max);
            }
            this._bounds.length.x = this._bounds.max.x - this._bounds.min.x;
            this._bounds.length.y = this._bounds.max.y - this._bounds.min.y;
            this._bounds.length.z = this._bounds.max.z - this._bounds.min.z;
            this._bounds.center.x = this._bounds.length.x * 0.5 + this._bounds.min.x;
            this._bounds.center.y = this._bounds.length.y * 0.5 + this._bounds.min.y;
            this._bounds.center.z = this._bounds.length.z * 0.5 + this._bounds.min.z;
            this._bounds.radius = Vector3D.distance(this._bounds.center, this._bounds.max);
            return this._bounds;
        }// end function

        public function set bounds(param1:Boundings3D) : void
        {
            this._bounds = param1;
            return;
        }// end function

        override public function getMaterialByName(param1:String, param2:Boolean = true) : Material3D
        {
            var _loc_3:Pivot3D = null;
            var _loc_4:Material3D = null;
            if (param1 == null || this._originalMaterial && this._originalMaterial.name == param1)
            {
                return this._originalMaterial;
            }
            if (param2)
            {
                for each (_loc_3 in children)
                {
                    
                    _loc_4 = _loc_3.getMaterialByName(param1);
                    if (_loc_4)
                    {
                        return _loc_4;
                    }
                }
            }
            return null;
        }// end function

        override public function updateTransforms(param1:Boolean, param2:Boolean, param3:int = 0) : void
        {
            super.updateTransforms(param1, param2, param3);
            this._updateBoundsScale = true;
            return;
        }// end function

        override public function get inView() : Boolean
        {
            return this.visible && !isHide;
        }// end function

        public function getScreenRect(param1:Rectangle = null, param2:Camera3D = null, param3:Rectangle = null) : Rectangle
        {
            var _loc_4:Boolean = false;
            if (!this._bounds)
            {
                return null;
            }
            if (!param1)
            {
                param1 = new Rectangle();
            }
            if (!param3)
            {
                param3 = Global3D.scene.viewPort;
            }
            if (!param2)
            {
                param2 = Global3D.camera;
            }
            Global3D.temporal0.copyFrom(world);
            Global3D.temporal0.append(param2.viewProjection);
            var _loc_5:* = this.projectCorner(0, Global3D.temporal0);
            if (_loc_5.w > 0)
            {
                _loc_4 = true;
            }
            param1.setTo(_loc_5.x, _loc_5.y, _loc_5.x, _loc_5.y);
            var _loc_6:int = 1;
            while (_loc_6 < 8)
            {
                
                _loc_5 = this.projectCorner(_loc_6, Global3D.temporal0);
                if (_loc_5.w > 0)
                {
                    _loc_4 = true;
                }
                if (_loc_5.x < param1.x)
                {
                    param1.x = _loc_5.x;
                }
                if (_loc_5.y > param1.y)
                {
                    param1.y = _loc_5.y;
                }
                if (_loc_5.x > param1.width)
                {
                    param1.width = _loc_5.x;
                }
                if (_loc_5.y < param1.height)
                {
                    param1.height = _loc_5.y;
                }
                _loc_6++;
            }
            if (!_loc_4)
            {
                return null;
            }
            param1.y = -param1.y;
            param1.width = param1.width - param1.x;
            param1.height = -param1.height - param1.y;
            var _loc_7:* = param3.width * 0.5;
            var _loc_8:* = param3.height * 0.5;
            param1.x = param1.x * _loc_7 + _loc_7 + param3.x;
            param1.y = param1.y * _loc_8 + _loc_8 + param3.y;
            param1.width = param1.width * _loc_7;
            param1.height = param1.height * _loc_8;
            if (param1.x < 0)
            {
                param1.width = param1.width + param1.x;
                param1.x = 0;
            }
            if (param1.y < 0)
            {
                param1.height = param1.height + param1.y;
                param1.y = 0;
            }
            if (param1.right > param3.width)
            {
                param1.right = param3.width;
            }
            if (param1.bottom > param3.height)
            {
                param1.bottom = param3.height;
            }
            return param1;
        }// end function

        private function projectCorner(param1:int, param2:Matrix3D) : Vector3D
        {
            switch(param1)
            {
                case 0:
                {
                    _bCenter.setTo(this._bounds.min.x, this._bounds.min.y, this._bounds.min.z);
                    break;
                }
                case 1:
                {
                    _bCenter.setTo(this._bounds.max.x, this._bounds.min.y, this._bounds.min.z);
                    break;
                }
                case 2:
                {
                    _bCenter.setTo(this._bounds.min.x, this._bounds.max.y, this._bounds.min.z);
                    break;
                }
                case 3:
                {
                    _bCenter.setTo(this._bounds.max.x, this._bounds.max.y, this._bounds.min.z);
                    break;
                }
                case 4:
                {
                    _bCenter.setTo(this._bounds.min.x, this._bounds.min.y, this._bounds.max.z);
                    break;
                }
                case 5:
                {
                    _bCenter.setTo(this._bounds.max.x, this._bounds.min.y, this._bounds.max.z);
                    break;
                }
                case 6:
                {
                    _bCenter.setTo(this._bounds.min.x, this._bounds.max.y, this._bounds.max.z);
                    break;
                }
                case 7:
                {
                    _bCenter.setTo(this._bounds.max.x, this._bounds.max.y, this._bounds.max.z);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return Utils3D.projectVector(param2, _bCenter);
        }// end function

        override public function draw(param1:Boolean = true, param2:ShaderBase = null) : void
        {
            var _loc_3:int = 0;
            if (!_scene)
            {
                return;
            }
            if (_visible && !this.isHide && this.material.materialParams.colorOffsetValue[3] > 0)
            {
                this.render.draw(this, param2);
            }
            super.draw(param1, param2);
            return;
        }// end function

        override public function set alpha(param1:Number) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_2:* = this.material.materialParams;
            if (_loc_2.alphaBaseValue != param1)
            {
                _loc_2.setAlphaBase(param1);
            }
            if (param1 < 1)
            {
                _loc_3 = this._originalMaterial.materialParams.blendMode;
                if (_loc_3 != EBlendType.BLEND_ALPHA0)
                {
                    this.setMateiralBlendMode(EBlendType.BLEND_ALPHA0);
                    this._oldBlendMode = _loc_3;
                }
                _loc_4 = this.layer;
                if (_loc_4 < Layer3DManager.modelLayer2)
                {
                    this.setLayer(Layer3DManager.modelLayer2, false);
                    this._oldLayer = _loc_4;
                }
            }
            else if (_loc_2.unlevelAlpha == 1)
            {
                if (this.layer != this._oldLayer)
                {
                    this.setLayer(this._oldLayer, false);
                }
                if (this._oldBlendMode != this._originalMaterial.materialParams.blendMode)
                {
                    this.setMateiralBlendMode(this._oldBlendMode);
                }
            }
            return;
        }// end function

        override public function get alpha() : Number
        {
            return this.material.materialParams.alphaBaseValue;
        }// end function

        public function get maskEnable() : Boolean
        {
            return this._originalMaterial.materialParams.enableMask;
        }// end function

        public function set maskEnable(param1:Boolean) : void
        {
            this._originalMaterial.materialParams.enableMask = param1;
            return;
        }// end function

        public function get xrayEnable() : Boolean
        {
            return this._originalMaterial.materialParams.enableXray;
        }// end function

        public function set xrayEnable(param1:Boolean) : void
        {
            this._originalMaterial.materialParams.enableXray = param1;
            if (this._originalMaterial != this.material)
            {
                this.material.materialParams.enableXray = param1;
            }
            return;
        }// end function

        override public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
        {
            super.removeEventListener(param1, param2, param3);
            switch(param1)
            {
                case MouseEvent3D.MOUSE_DOWN:
                {
                    if (!hasEventListener(param1))
                    {
                        _eventFlags = _eventFlags | MOUSE_DOWN;
                        _eventFlags = _eventFlags - MOUSE_DOWN;
                    }
                    break;
                }
                case MouseEvent3D.MOUSE_MOVE:
                {
                    if (!hasEventListener(param1))
                    {
                        _eventFlags = _eventFlags | MOUSE_MOVE;
                        _eventFlags = _eventFlags - MOUSE_MOVE;
                    }
                    break;
                }
                case MouseEvent3D.MOUSE_OUT:
                {
                    if (!hasEventListener(param1))
                    {
                        _eventFlags = _eventFlags | MOUSE_OUT;
                        _eventFlags = _eventFlags - MOUSE_OUT;
                    }
                    break;
                }
                case MouseEvent3D.MOUSE_OVER:
                {
                    if (!hasEventListener(param1))
                    {
                        _eventFlags = _eventFlags | MOUSE_OVER;
                        _eventFlags = _eventFlags - MOUSE_OVER;
                    }
                    break;
                }
                case MouseEvent3D.MOUSE_UP:
                {
                    if (!hasEventListener(param1))
                    {
                        _eventFlags = _eventFlags | MOUSE_UP;
                        _eventFlags = _eventFlags - MOUSE_UP;
                    }
                    break;
                }
                case Engine3dEventName.MATERIAL_CHANGE:
                {
                    if (!hasEventListener(param1))
                    {
                        _eventFlags = _eventFlags | MATERIAL_CHANGE;
                        _eventFlags = _eventFlags - MATERIAL_CHANGE;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override public function update(param1:int = 0) : void
        {
            if (TimeControler.stageTime == _preFrame)
            {
                return;
            }
            super.update(param1);
            return;
        }// end function

        public function changeToAdditionalMaterial(param1:ShaderBase) : void
        {
            if (this.material == param1)
            {
                return;
            }
            var _loc_2:* = this._additionMaterialList.indexOf(param1);
            if (_loc_2 == -1)
            {
                this._additionMaterialList.push(param1);
            }
            this.material.clear();
            this.material = param1;
            var _loc_3:* = param1.materialParams;
            var _loc_4:* = this._originalMaterial.materialParams;
            _loc_3.uvRepeat = _loc_4.uvRepeat;
            _loc_3.sourceFactor = _loc_4.sourceFactor;
            _loc_3.destFactor = _loc_4.destFactor;
            _loc_3.colorKillvalue = _loc_4.colorKillvalue;
            _loc_3.alphaKillvalue = _loc_4.alphaKillvalue;
            _loc_3.skinNum = _loc_4.skinNum;
            _loc_3.enableXray = _loc_4.enableXray;
            this.alpha = 1;
            if (param1 is UseOriTexShaderbase && UseOriTexShaderbase(param1).useOriginTexture)
            {
                _loc_3.setFragmentFilter(_loc_4.fragmentFilter);
            }
            this.material.materialParams.needRegetBone = true;
            return;
        }// end function

        public function removeAdditionalMaterial(param1:ShaderBase) : void
        {
            var _loc_3:ShaderBase = null;
            var _loc_2:* = this._additionMaterialList.indexOf(param1);
            if (_loc_2 != -1)
            {
                this._additionMaterialList.splice(_loc_2, 1);
                param1.clear();
            }
            if (this._additionMaterialList.length == 0)
            {
                if (this.material != this._originalMaterial)
                {
                    this.material = this._originalMaterial;
                    this.material.materialParams.reInitFragParams();
                    this.material.materialParams.needRegetBone = true;
                }
            }
            else
            {
                _loc_3 = this._additionMaterialList[(this._additionMaterialList.length - 1)];
                if (this.material != _loc_3)
                {
                    this.changeToAdditionalMaterial(_loc_3);
                }
            }
            return;
        }// end function

    }
}
